<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
<div class="page_right indexpage_right">
    <div class="indexpage_right_date">
        <p style="text-align:left; text-indent:38px;">
            <span>日期</span>
            <input class="Wdate" type="text" id="stime" onClick="WdatePicker()">
            <span>至</span>
            <input class="Wdate" type="text" id="etime" onClick="WdatePicker()">
            <a class="placeAndEquipment_search" href="javascript:;">查询</a>
        </p>
        <ul class="timeType">
            <li><a href="javascript:;" class="${cur==1?'cur':''}">今日</a></li>
            <li><a href="javascript:;" class="${cur==2?'cur':''}">本周</a></li>
            <li><a href="javascript:;" class="${cur==3?'cur':''}">本月</a></li>
            <li><a href="javascript:;" class="${cur==4?'cur':''}">昨日</a></li>
            <li><a href="javascript:;" class="${cur==5?'cur':''}">上周</a></li>
            <li><a href="javascript:;" class="${cur==6?'cur':''}">上月</a></li>
            <li><a class="numbercur" href="javascript:;" class="${cur==7?'cur':''}">按次数</a></li>
            <li><a href="javascript:;" class="${cur==8?'cur':''}">总账</a></li>
        </ul>


        <c:if test="${not empty Accountids}">
            <%--动态次数列表 （开始）--%>
            <div class="account_changlong_onenumber_dv1">
                <div class="account_changlong_onenumber1_leftbtn"></div>
                <div class="account_changlong_onenumberdv1">
                    <ul class="account_changlong_onenumber1"></ul>
                </div>
                <div class="account_changlong_onenumber1_rightbtn"></div>
            </div>

            <div class="account_clear"></div>
            <div class="account_changlong_onenumber_dv2">
                <div class="account_changlong_onenumber2_leftbtn"></div>
                <div class="account_changlong_onenumberdv2">
                    <div></div>
                </div>
                <div class="account_changlong_onenumber2_rightbtn"></div>
            </div>


            <div class="account_changlong_onenumberquery">查看全部次数</div>
            <%--动态次数列表 （结束）--%>
        </c:if>

    </div>
    <%@ include file="/WEB-INF/jsp/web/v2/account/_rightContent1.jsp" %>
</div>
<script src="${basePath}resources/js/v2/accountClick.js"></script>

<script type="application/javascript">
    //清零次数
    var balanceid = ${AccountSummary.cashIncome};
    //依据选择周期跳转
    var uri = "${basePath}v2/account/";
    var place = "${placeId}";
    var device = "${deviceId}";
    if (place == null) {
        place = 0;
    } else if (device == null) {
        device = 0;
    }

    $(".timeType a").each(function (n) {
        $(this).click(function () {
            getUri1(uri, n, place, device);
        });
    });

    //按次数查询账目
    function findAccountByFrequency(frequencyid) {
        //不能重复提交请求
        if(frequencyid != balanceid){
            $.ajax({
                url: '${basePath}v2/account/showtozerobalance',
                type: 'POST',
                data: {"placeId":${placeId}, "deviceId":${deviceId}, "balanceid": frequencyid},
                error: function (response) {
                    $errorMsg(response);
                },
                success: function (ret) {
                    balanceid = ret.balanceid;
                    bindingParam(ret);
                }
            });
        }


    }


    //按总账查询账目
    $("#GC_generaaccount_onclick").click(function () {
        $.ajax({
            url: '${basePath}v2/account/showgeneraaccount',
            type: 'POST',
            data: {"placeId":${placeId}, "deviceId":${deviceId}},
            error: function (response) {
                $errorMsg(response);
            },
            success: function (ret) {
                bindingParam(ret);
            }
        });
    });

</script>

<%--动态加载次数序号--%>
<script>

    var accountids = ${Accountids};
    var indexmax = accountids.length;
    var indexmaxcur = indexmax;
    var u1li = "";

    for (var i = indexmax; i > 0; i--) {
        u1li += "<li><a GCclick='GC_a_click' name=" + accountids[indexmax - i] + " href='javascript:;'>" + i + "</a></li>";
    }
    $(".account_changlong_onenumber1").append(u1li).css({"width": 110 * indexmax + "px"});
    $(".account_changlong_onenumber1 li:eq(0) a").addClass("cur");

    //移动效果
    function numberState(flag) {
        if (indexmax > 7) {
            if (indexmaxcur > 7) {
                $(".account_changlong_onenumber1 li").children("a").removeClass("cur");
                $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ")").children("a").addClass("cur");

                if (flag) {
                    var frequencyid = $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ") a").attr("name");
                    findAccountByFrequency(frequencyid);
                }

                $(".account_changlong_onenumber1").css({
                    "transition": "all 0.3s",
                    "left": -110 * (indexmax - indexmaxcur) + "px"
                });
            } else if (indexmaxcur <= 7) {
                $(".account_changlong_onenumber1").css({
                    "transition": "all 0.3s",
                    "left": -110 * (indexmax - 7) + "px"
                });
                $(".account_changlong_onenumber1 li").children("a").removeClass("cur");
                $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ")").children("a").addClass("cur");


                if (flag) {
                    var frequencyid = $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ") a").attr("name");
                    findAccountByFrequency(frequencyid);
                }


            }
        } else {
            $(".account_changlong_onenumber1").css({"transition": "all 0.3s", "left": "0px"});
            $(".account_changlong_onenumber1 li").children("a").removeClass("cur");
            $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ")").children("a").addClass("cur");


            if (flag) {
                var frequencyid = $(".account_changlong_onenumber1 li:eq(" + (indexmax - indexmaxcur) + ") a").attr("name");
                findAccountByFrequency(frequencyid);
            }


        }
    }

    //左边按钮
    $(".account_changlong_onenumber1_leftbtn").on("click", function () {
        indexmaxcur++;
        if (indexmaxcur >= indexmax) {
            indexmaxcur = indexmax;
        }
        numberState(true);
    });
    //右边按钮
    $(".account_changlong_onenumber1_rightbtn").on("click", function () {
        indexmaxcur--;
        if (indexmaxcur <= 1) {
            indexmaxcur = 1;
        }
        numberState(true);
    });
    //随机点击
    $(".account_changlong_onenumber1 li").each(function (n) {
        $(this).click(function () {
            indexmaxcur = indexmax - n;
            numberState(true);
        })
    });
    //查看全部次数
    $(".account_clear, .account_changlong_onenumber_dv2").hide();
    $(".account_changlong_onenumberquery").on("click", function(){
        var unumb=1;
        $(".account_changlong_onenumberdv2 div").css({"transition":"all 0.3s","left":-770*(unumb-1)+"px"});
        if($(".account_changlong_onenumber_dv2").is(":hidden")){
            addallu2();
            $(".account_clear, .account_changlong_onenumber_dv2").stop().show();
            $(".account_changlong_onenumberdv2 li").children("a").removeClass("cur");
            $(".account_changlong_onenumberdv2 li:eq("+(indexmax-indexmaxcur)+") a").addClass("cur");

            //随机点击
            $(".account_changlong_onenumberdv2 li").each(function(m){
                $(this).click(function(){
                    indexmaxcur=indexmax-m;
                    $(".account_changlong_onenumberdv2 li").children("a").removeClass("cur");
                    $(".account_changlong_onenumberdv2 li:eq("+(indexmax-indexmaxcur)+") a").addClass("cur");
                    $(".account_clear, .account_changlong_onenumber_dv2").stop().hide();
                    numberState();
                    unumb=1;
                    $(".account_changlong_onenumberdv2 div").css({"transition":"all 0.3s","left":-770*(unumb-1)+"px"});
                })
            });
            //左边按钮
            var unumber=$(".account_changlong_onenumberdv2 ul").length;
            $(".account_changlong_onenumber2_leftbtn").on("click", function(){

                unumb--;
                if(unumb<=1){
                    unumb=1;
                }
                $(".account_changlong_onenumberdv2 div").css({"transition":"all 0.3s","left":-770*(unumb-1)+"px"});
            });
            //右边按钮
            $(".account_changlong_onenumber2_rightbtn").on("click", function(){
                unumb++;
                if(unumb>=unumber){
                    unumb=unumber;
                }
                $(".account_changlong_onenumberdv2 div").css({"transition":"all 0.3s","left":-770*(unumb-1)+"px"});
            });

        }else{
            $(".account_clear, .account_changlong_onenumber_dv2").stop().hide();
        }
        numberState(false);
    });

    //加载次数
    var u2numb = parseInt(indexmax / 21);
    var u2numb_index = indexmax % 21;
    var u2li = "";
    var u2li1 = "";
    var allu2 = "";

    function addallu2() {
        if (!$(".account_changlong_onenumberdv2 div ul").hasClass("account_changlong_onenumber2")) {
            if (u2numb > 0) {
                if (u2numb_index > 0) {
                    for (var x = u2numb; x > 0; x--) {
                        for (var y = (21 * x + u2numb_index); y > (21 * (x - 1) + u2numb_index); y--) {
                            u2li += "<li><a GCclick='GC_a_click' name=" + accountids[indexmax - y] + " href='javascript:;'>" + y + "</a></li>";
                        }
                        allu2 += "<ul class='account_changlong_onenumber2'>" + u2li + "</ul>";
                    }

                    for (var n = u2numb_index; n > 0; n--) {
                        u2li1 += "<li><a name=" + accountids[indexmax - n] + " href='javascript:;'>" + n + "</a></li>";
                    }
                    allu2 += "<ul class='account_changlong_onenumber2'>" + u2li1 + "</ul>";
                } else {
                    for (var x = u2numb; x > 0; x--) {
                        for (var y = (21 * x + u2numb_index); y > (21 * (x - 1) + u2numb_index); y--) {
                            u2li += "<li><a GCclick='GC_a_click' name=" + accountids[indexmax - y] + " href='javascript:;'>" + y + "</a></li>";
                        }
                        return allu2 += "<ul class='account_changlong_onenumber2'>" + u2li + "</ul>";
                    }
                }
                $(".account_changlong_onenumberdv2 div").append(allu2).css({"width": 770 * (u2numb + 1) + "px"});
                $(".account_changlong_onenumberdv2 li").children("a").removeClass("cur");
                $(".account_changlong_onenumberdv2 li:eq(" + (indexmax - indexmaxcur) + ") a").addClass("cur");

            } else {
                for (var j = indexmax; j > 0; j--) {
                    u2li += "<li><a GCclick='GC_a_click' name=" + accountids[indexmax - j] + " href='javascript:;'>" + j + "</a></li>";
                }
                $(".account_changlong_onenumberdv2 div").append("<ul class='account_changlong_onenumber2'>" + u2li + "</ul>").css({"width": 770 * (u2numb + 1) + "px"});
                $(".account_changlong_onenumberdv2 li").children("a").removeClass("cur");
                $(".account_changlong_onenumberdv2 li:eq(" + (indexmax - indexmaxcur) + ") a").addClass("cur");

            }

            $("a[GCclick='GC_a_click']").click(function () {
                var frequencyid = $(this).attr("name");
                findAccountByFrequency(frequencyid);
            });

        }
    }
</script>